package com.tyl.dao.role;

import com.tyl.dao.BaseDao;
import com.tyl.pojo.Role;
import com.tyl.service.role.RoleService;
import com.tyl.service.role.RoleServiceImpl;
import org.junit.jupiter.api.Test;

import java.sql.Connection;
import java.sql.PreparedStatement;
import java.sql.ResultSet;
import java.sql.SQLException;
import java.util.ArrayList;
import java.util.List;

public class RoleDaoImpl implements RoleDao{
    public List<Role> getRoleList(Connection connection) throws SQLException{
        PreparedStatement pstm=null;
        ResultSet rs=null;
        Object[]prams={};
        ArrayList<Role> roleList = new ArrayList<Role>();
        String sql="select *from smbms_role";
        System.out.println(sql.toString());
        if(connection!=null){
            try {
                rs = BaseDao.execute(connection, pstm, sql, rs, prams);
                while (rs.next()){
                    Role role=new Role();
                    role.setId(rs.getInt("id"));
                    role.setRoleCode(rs.getString("roleCode"));
                    role.setRoleName(rs.getString("roleName"));
                    role.setCreatedBy(rs.getInt("createdBy"));
                    role.setCreationDate(rs.getDate("creationDate"));
                    role.getModifyBy(rs.getInt("modifyBy"));
                    role.setCreationDate(rs.getDate("modifyDate"));
                    roleList.add(role);
                }
            } catch (SQLException e) {
                e.printStackTrace();
            }finally {
                BaseDao.closeResource(null,pstm,rs);
            }
        }
        return roleList;
    }
    @Test
    public  void test(){
        RoleService roleService=new RoleServiceImpl();
        List<Role> roleList = roleService.getRoleList();
        System.out.println(roleList);
    }
}
